Reads data from an open sequential file.
オープン済みの順編成ファイルからデータを読み取ります。
Input #FileNumber As Integer; var1[, var2[, var3[,...]]]
Input #FileNumber As Integer; var1[, var2[, var3[,...]]]
FileNumber: Number of the file that contains the data that you want to read. The file must be opened with the Open statement using the key word INPUT.
FileNumber: 読み取るデータを含むファイルの番号。読み取るファイルは、Open ステートメントに INPUT キーワードを指定して、事前にオープンしておく必要があります。
var: A numeric or string variable that you assign the values read from the opened file to.
var: オープン済みのファイルから読み取った値を格納する、数値型ないし文字列型の変数。
The Input# statement reads numeric values or strings from an open file and assigns the data to one or more variables. A numeric variable is read up to the first carriage return (Asc=13), line feed (Asc=10), space, or comma. String variables are read to up to the first carriage return (Asc=13), line feed (Asc=10), or comma.
Input# ステートメントは、オープン済みのファイルから数値ないし文字列を読み取り、これらの値を 1 つまたは複数の変数に格納します。数値は、次に来るキャリッジリターン (ASC=13)、ラインフィード (ASC=10)、スペース、コンマまでのデータが、1 度に読み取られます。文字列は、次に来るコードがキャリッジリターン (ASC=13)、ラインフィード (ASC=10)、コンマまでのデータが、1 度に読み取られます。
Data and data types in the opened file must appear in the same order as the variables that are passed in the "var" parameter. If you assign non-numeric values to a numeric variable, "var" is assigned a value of "0".
オープン済みファイル中にあるデータおよびデータ型は、「var」に指定する変数の順序と一致している必要があります。数値以外のデータを数値変数に代入すると、「var」の変数には「0」値が格納されます。
Records that are separated by commas cannot be assigned to a string variable. Quotation marks (") in the file are disregarded as well. If you want to read these characters from the file, use the Line Input# statement to read pure text files (files containing only printable characters) line by line.
コンマで区切られているレコードを文字列値に割り当てることはできません。 同じようにファイル内の引用符 (") も無視されます。 ファイルからこのような文字を読み取る場合は Line Input# 文を使用し、テキストファイル (印刷可能な文字のみで構成されるファイル) を読み取ります。
If the end of the file is reached while reading a data element, an error occurs and the process is aborted.
データの読み取り中にファイル末尾に到達すると、エラーが発生してプロセスは終了させられます。
Sub ExampleWorkWithAFile
Sub ExampleWorkWithAFile
Dim iNumber As Integer
Dim iNumber As Integer
Dim sLine As String
Dim sLine As String
Dim aFile As String
Dim aFile As String
Dim sMsg as String
Dim sMsg as String
aFile = "c:\data.txt"
aFile = "c:\data.txt"
iNumber = Freefile
iNumber = Freefile
Open aFile For Output As #iNumber
Open aFile For Output As #iNumber
Print #iNumber, "This is a line of text"
Print #iNumber, "This is a line of text"
Print #iNumber, "This is another line of text"
Print #iNumber, "This is another line of text"
Close #iNumber
Close #iNumber
iNumber = Freefile
iNumber = Freefile
Open aFile For Input As iNumber
Open aFile For Input As iNumber
While not eof(iNumber)
While not eof(iNumber)
Line Input #iNumber, sLine
Line Input #iNumber, sLine
If sLine <>"" then
If sLine <>"" then
sMsg = sMsg & sLine & chr(13)
sMsg = sMsg & sLine & chr(13)
end if
end if
wend
Wend
Close #iNumber
Close #iNumber
Msgbox sMsg
Msgbox sMsg
End Sub
End Sub